//封装 axios
import axios from 'axios';
import config from '../config/config';
//创建实例对象
let instance = axios.create({
    baseURL: 'http://127.0.0.1'
});

//声明响应拦截器
instance.interceptors.response.use(response => {
    //解构赋值
    let {books, totalPage, page} = response.data.data; 
    //更新当前的页码数
    config.page = page;
    config.books = books;
    config.totalPage = totalPage;
    //返回 response 对象
    return response;
}, error => {
    console.log(error);
    alert('请求失败~~');
    //中断 promise 链条
    return new Promise(() => {})
})

//暴露
export default instance;